<template>
    <div class="app-container">
      <div style="width: 60%;margin:0 auto;">
        <el-form :model="formData" :rules="rules" ref="elForm" label-width="85px">
          <el-form-item label="公司名称" prop="company_name">
            <el-input
              v-model="formData.company_name"
              placeholder="请输入公司名称"
              clearable
            />
          </el-form-item>

          <el-form-item label="公司电话" prop="company_tel">
            <el-input
              v-model="formData.company_tel"
              placeholder="请输入公司电话"
              clearable
            />
          </el-form-item>

          <el-form-item label="公司邮箱" prop="company_email">
            <el-input
              v-model="formData.company_email"
              placeholder="请输入公司邮箱"
              clearable
            />
          </el-form-item>

          <el-form-item label="公司介绍" prop="company_introduction">
            <el-input
              type="textarea"
              :autosize="{ minRows: 3, maxRows: 5}"
              v-model="formData.company_introduction"
              placeholder="请输入公司介绍"
            />
          </el-form-item>

          <el-form-item>
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
          </el-form-item>
        </el-form>

      </div>
    </div>
</template>

<script>
    import { getCompanyInfo, updateCompanyInfo } from '@/api/base/article';
    export default {
        name: "companyIndex",
        data() {
          return{
            formData:{

            },
            rules:{
              company_name: [{ required: true, message: "公司名称不能为空", trigger: "blur" }]
            }
          }
        },
        mounted() {
          this.getInfo();
        },
        methods:{
          // 修改公司信息
          submitForm() {
            this.$refs["elForm"].validate(valid => {
              if (valid) {
                updateCompanyInfo(this.formData).then(res=>{
                  if(res.code == 200) {
                    this.$message.success('操作成功。');
                    this.getInfo();
                  } else {
                    this.$message.error(res.msg);
                  }
                });
              } else {
                return;
              }
            });
          },
          cancel() {

          },
          // 获取公司信息
          getInfo() {
            getCompanyInfo(1).then(res=>{
               this.formData = res.data;
            });
          }
        }
    }
</script>

<style scoped>

</style>
